<?php

use \Doraemon\model\Position\DailyReport as MHhzPositionDailyReport;

ini_set('display_errors', 1);
require_once '/data/wwwroot/g_vendor/autoload.php';


$config = [
    59482 => [
        '2022/3/4' => [151406,4999],
        '2022/3/5' => [148893,4683],
        '2022/3/6' => [147393,4772],
        '2022/3/7' => [156705,5298],
        '2022/3/8' => [155284,5223],
        '2022/3/9' => [150753,4986],
        '2022/3/10' => [149395,4897],
    ],
    59662 => [
        '2022/3/8' => [73298,2435],
        '2022/3/9' => [74005,2416],
        '2022/3/10' => [75083,2502],
        '2022/3/11' => [74692,2334],
        '2022/3/12' => [72743,2363],
        '2022/3/13' => [73017,2402],
        '2022/3/14' => [69553,2101],
    ],
    59841 => [
        '2022/3/15' => [77699,2576],
        '2022/3/16' => [77932,2603],
        '2022/3/17' => [78854,2669],
        '2022/3/18' => [79034,2708],
        '2022/3/19' => [76643,2558],
        '2022/3/20' => [76987,2402],
        '2022/3/21' => [76745,2308],
    ],
    60029 => [
        '2022/3/19' => [156278,5002],
        '2022/3/20' => [153034,4888],
        '2022/3/21' => [158893,5102],
        '2022/3/22' => [157749,5330],
        '2022/3/23' => [158203,5259],
        '2022/3/24' => [155998,5235],
        '2022/3/25' => [153797,5126],
    ],
    60048 => [
        '2022/3/22' => [77614,2478],
        '2022/3/23' => [78032,2543],
        '2022/3/24' => [78284,2522],
        '2022/3/25' => [79022,2603],
        '2022/3/26' => [77019,2432],
        '2022/3/27' => [76964,2469],
        '2022/3/28' => [76366,2301],
    ],
    59840 => [
        '2022/3/14' => [1173963,30241],
    ],
    59661 => [
        '2022/3/8' => [859683,20905],
    ],
    59485 => [
        '2022/3/7' => [403206,10957],
    ],
];




foreach ($config as $config_id => $list) {
    $exists = MHhzPositionDailyReport::select("*", ['config_id' => $config_id]);
    $exists = array_column($exists, null, 'day_str');
    foreach ($list as $day => $item) {
        $shows = $item[0] ?? 0;
        $clicks = $item[1] ?? 0;
        $dis_show_user = $item[2] ?? 0;
        $dis_click_user = $item[3] ?? 0;
        $day_str = date("Ymd", strtotime($day));
        $up = compact('day_str', 'config_id', 'shows', 'clicks', 'dis_show_user', 'dis_click_user');
        if (isset($exists[$day_str])) {
            MHhzPositionDailyReport::update($up, ['id' => $exists[$day_str]['id']]);
        } else {
            MHhzPositionDailyReport::insert($up);
        }
    }
}
